-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools: add JSDoc ESLint plugin #38288
Conversation
Start with a single rule (check-tag-names) and configure it to limit the number of required fixes.
FWIW, this reduces the number of files, but keeps the same number of lines. |
Yes, I could pass the files through |
Is there a reason to bundle/minify here, it may be harder to understand what is going on if we need to debug this |
|
@@ -0,0 +1,7 @@ | |||
"use strict";var e=require("lodash"),t=require("fs"),n=require("path"),r=require("@eslint/eslintrc"),o=require("module"),s=require("glob-parent"),a=require("is-glob"),i=require("minimatch"),c=require("debug"),l=require("eslint-scope"),u=require("eslint-visitor-keys"),p=require("espree"),d=require("globals"),f=require("util"),m=require("ajv"),g=require("eslint-utils"),h=require("assert"),y=require("levn"),x=require("esquery"),b=require("esutils"),E=require("functional-red-black-tree"),S=require("regexpp"),C=require("ignore"),v=require("natural-compare"),A=require("doctrine"),k=require("imurmurhash"),w=require("file-entry-cache"),P=require("json-stable-stringify-without-jsonify"),T=require("semver");function I(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var F=I(e),D=I(t),O=I(n),B=I(r),N=I(o),j=I(s),L=I(a),R=I(i),M=I(c),_=I(l),$=I(u),q=I(p),U=I(d),V=I(f),W=I(m),G=I(g),z=I(h),J=I(y),K=I(x),Y=I(b),H=I(E),X=I(S),Q=I(C),Z=I(v),ee=I(A),te=I(k),ne=I(w),re=I(P),oe=I(T),se="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ae(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ie(e){var t={exports:{}};return e(t,t.exports),t.exports}function ce(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var le=ie((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.rewireSpecs=t.rewireSource=t.seedTokens=t.seedSpec=t.seedBlock=t.splitLines=t.splitSpace=t.isSpace=void 0,t.isSpace=function(e){return/^\s+$/.test(e)},t.splitSpace=function(e){const t=e.match(/^\s+/);return null==t?["",e]:[e.slice(0,t[0].length),e.slice(t[0].length)]},t.splitLines=function(e){return e.split(/\r?\n/)},t.seedBlock=function(e={}){return Object.assign({description:"",tags:[],source:[],problems:[]},e)},t.seedSpec=function(e={}){return Object.assign({tag:"",name:"",type:"",optional:!1,description:"",problems:[],source:[]},e)},t.seedTokens=function(e={}){return Object.assign({start:"",delimiter:"",postDelimiter:"",tag:"",postTag:"",name:"",postName:"",type:"",postType:"",description:"",end:""},e)},t.rewireSource=function(e){const t=e.source.reduce(((e,t)=>e.set(t.number,t)),new Map);for(const n of e.tags)n.source=n.source.map((e=>t.get(e.number)));return e},t.rewireSpecs=function(e){const t=e.tags.reduce(((e,t)=>t.source.reduce(((e,t)=>e.set(t.number,t)),e)),new Map);return e.source=e.source.map((e=>t.get(e.number)||e)),e}}));const ue=/^@\S+/;var pe=function({fence:e="```"}={}){const t=function(e){return"string"==typeof e?t=>t.split(e).length%2==0:e}(e),n=(e,n)=>t(e)?!n:n;return function(e){const t=[[]];let r=!1;for(const o of e)ue.test(o.tokens.description)&&!r?t.push([o]):t[t.length-1].push(o),r=n(o.tokens.description,r);return t}};var de=Object.defineProperty({default:pe},"__esModule",{value:!0}),fe=ie((function(e,t){var n;Object.defineProperty(t,"__esModule",{value:!0}),t.Markers=void 0,(n=t.Markers||(t.Markers={})).start="/**",n.nostart="/***",n.delim="*",n.end="*/"}));var me=function({startLine:e=0}={}){let t=null,n=e;return function(e){let r=e;const o=le.seedTokens();if([o.start,r]=le.splitSpace(r),null===t&&r.startsWith(fe.Markers.start)&&!r.startsWith(fe.Markers.nostart)&&(t=[],o.delimiter=r.slice(0,fe.Markers.start.length),r=r.slice(fe.Markers.start.length),[o.postDelimiter,r]=le.splitSpace(r)),null===t)return n++,null;const s=r.trimRight().endsWith(fe.Markers.end);if(""===o.delimiter&&r.startsWith(fe.Markers.delim)&&!r.startsWith(fe.Markers.end)&&(o.delimiter=fe.Markers.delim,r=r.slice(fe.Markers.delim.length),[o.postDelimiter,r]=le.splitSpace(r)),s){const e=r.trimRight();o.end=r.slice(e.length-fe.Markers.end.length),r=e.slice(0,-fe.Markers.end.length)}if(o.description=r,t.push({number:n,source:e,tokens:o}),n++,s){const e=t.slice();return t=null,e}return null}},ge=Object.defineProperty({default:me},"__esModule",{value:!0});var he=function({tokenizers:e}){return function(t){var n;let r=le.seedSpec({source:t});for(const t of e)if(r=t(r),null===(n=r.problems[r.problems.length-1])||void 0===n?void 0:n.critical)break;return r}},ye=Object.defineProperty({default:he},"__esModule",{value:!0});var xe=function(){return e=>{const{tokens:t}=e.source[0],n=t.description.match(/\s*(@(\S+))(\s*)/);return null===n?(e.problems.push({code:"spec:tag:prefix",message:'tag should start with "@" symbol',line:e.source[0].number,critical:!0}),e):(t.tag=n[1],t.postTag=n[3],t.description=t.description.slice(n[0].length),e.tag=n[2],e)}},be=Object.defineProperty({default:xe},"__esModule",{value:!0});var Ee=function(e="compact"){const t=function(e){return"compact"===e?e=>e.map(Se).join(""):"preserve"===e?e=>e.join("\n"):e}(e);return e=>{let n=0,r=[];for(const[t,{tokens:o}]of e.source.entries()){let s="";if(0===t&&"{"!==o.description[0])return e;for(const e of o.description)if("{"===e&&n++,"}"===e&&n--,s+=e,0===n)break;if(r.push([o,s]),0===n)break}if(0!==n)return e.problems.push({code:"spec:type:unpaired-curlies",message:"unpaired curlies",line:e.source[0].number,critical:!0}),e;const o=[],s=r[0][0].postDelimiter.length;for(const[e,[t,n]]of r.entries())""!==n&&(t.type=n,e>0&&(t.type=t.postDelimiter.slice(s)+n,t.postDelimiter=t.postDelimiter.slice(0,s)),[t.postType,t.description]=le.splitSpace(t.description.slice(n.length)),o.push(t.type));return o[0]=o[0].slice(1),o[o.length-1]=o[o.length-1].slice(0,-1),e.type=t(o),e}};const Se=e=>e.trim();var Ce=Object.defineProperty({default:Ee},"__esModule",{value:!0});var ve=function(){const e=(e,{tokens:t},n)=>""===t.type?e:n;return t=>{const{tokens:n}=t.source[t.source.reduce(e,0)],r=n.description.trimLeft(),o=r.split('"');if(o.length>1&&""===o[0]&&o.length%2==1)return t.name=o[1],n.name=`"${o[1]}"`,[n.postName,n.description]=le.splitSpace(r.slice(n.name.length)),t;let s,a=0,i="",c=!1;for(const e of r){if(0===a&&le.isSpace(e))break;"["===e&&a++,"]"===e&&a--,i+=e}if(0!==a)return t.problems.push({code:"spec:name:unpaired-brackets",message:"unpaired brackets",line:t.source[0].number,critical:!0}),t;const l=i;if("["===i[0]&&"]"===i[i.length-1]){c=!0,i=i.slice(1,-1);const e=i.split("=");if(i=e[0].trim(),void 0!==e[1]&&(s=e.slice(1).join("=").trim()),""===i)return t.problems.push({code:"spec:name:empty-name",message:"empty name",line:t.source[0].number,critical:!0}),t;if(""===s)return t.problems.push({code:"spec:name:empty-default",message:"empty default value",line:t.source[0].number,critical:!0}),t;if(!((u=s)&&u.startsWith('"')&&u.endsWith('"'))&&/=(?!>)/.test(s))return t.problems.push({code:"spec:name:invalid-default",message:"invalid default value syntax",line:t.source[0].number,critical:!0}),t}var u;return t.optional=c,t.name=i,n.name=l,void 0!==s&&(t.default=s),[n.postName,n.description]=le.splitSpace(r.slice(n.name.length)),t}},Ae=Object.defineProperty({default:ve},"__esModule",{value:!0}),ke=ie((function(e,t){function n(e){return"compact"===e?r:"preserve"===e?a:e}function r(e){return e.map((({tokens:{description:e}})=>e.trim())).filter((e=>""!==e)).join(" ")}Object.defineProperty(t,"__esModule",{value:!0}),t.getJoiner=void 0,t.default=function(e="compact"){const t=n(e);return e=>(e.description=t(e.source),e)},t.getJoiner=n;const o=(e,{tokens:t},n)=>""===t.type?e:n,s=({tokens:e})=>(""===e.delimiter?e.start:e.postDelimiter.slice(1))+e.description;function a(e){if(0===e.length)return"";""===e[0].tokens.description&&e[0].tokens.delimiter===fe.Markers.start&&(e=e.slice(1));const t=e[e.length-1];return void 0!==t&&""===t.tokens.description&&t.tokens.end.endsWith(fe.Markers.end)&&(e=e.slice(0,-1)),(e=e.slice(e.reduce(o,0))).map(s).join("\n")}}));var we=function({startLine:e=0,fence:t="```",spacing:n="compact",tokenizers:r=[be.default(),Ce.default(n),Ae.default(),ke.default(n)]}={}){if(e<0||e%1>0)throw new Error("Invalid startLine");const o=ge.default({startLine:e}),s=de.default({fence:t}),a=ye.default({tokenizers:r}),i=ke.getJoiner(n),c=e=>""!=e.tokens.description.trim();return function(e){const t=[];for(const n of le.splitLines(e)){const e=o(n);if(null===e)continue;if(void 0===e.find(c))continue;const r=s(e),l=r.slice(1).map(a);t.push({description:i(r[0]),tags:l,source:e,problems:l.reduce(((e,t)=>e.concat(t.problems)),[])})}return t}},Pe=Object.defineProperty({default:we},"__esModule",{value:!0});var Te=function(){return e=>e.source.map((({tokens:e})=>function(e){return e.start+e.delimiter+e.postDelimiter+e.tag+e.postTag+e.type+e.postType+e.name+e.postName+e.description+e.end}(e))).join("\n")},Ie=Object.defineProperty({default:Te},"__esModule",{value:!0}),Fe=se&&se.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n};const De={start:0,tag:0,type:0,name:0},Oe=(e,{tokens:t})=>({start:t.delimiter===fe.Markers.start?t.start.length:e.start,tag:Math.max(e.tag,t.tag.length),type:Math.max(e.type,t.type.length),name:Math.max(e.name,t.name.length)}),Be=e=>"".padStart(e," ");var Ne=function(){let e,t=!1;function n(n){const r=Object.assign({},n.tokens);""!==r.tag&&(t=!0);const o=""===r.tag&&""===r.name&&""===r.type&&""===r.description;if(r.end===fe.Markers.end&&o)return r.start=Be(e.start+1),Object.assign(Object.assign({},n),{tokens:r});switch(r.delimiter){case fe.Markers.start:r.start=Be(e.start);break;case fe.Markers.delim:r.start=Be(e.start+1);break;default:r.delimiter="",r.start=Be(e.start+2)}if(!t)return r.postDelimiter=""===r.description?"":" ",Object.assign(Object.assign({},n),{tokens:r});const s={delim:!1,tag:!1,type:!1,name:!1};return""===r.description&&(s.name=!0,r.postName="",""===r.name&&(s.type=!0,r.postType="",""===r.type&&(s.tag=!0,r.postTag="",""===r.tag&&(s.delim=!0)))),r.postDelimiter=s.delim?"":" ",s.tag||(r.postTag=Be(e.tag-r.tag.length+1)),s.type||(r.postType=Be(e.type-r.type.length+1)),s.name||(r.postName=Be(e.name-r.name.length+1)),Object.assign(Object.assign({},n),{tokens:r})}return t=>{var{source:r}=t,o=Fe(t,["source"]);return e=r.reduce(Oe,Object.assign({},De)),le.rewireSource(Object.assign(Object.assign({},o),{source:r.map(n)}))}},je=Object.defineProperty({default:Ne},"__esModule",{value:!0}),Le=se&&se.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n};var Re=function(e){let t;const n=n=>{if(void 0===t){const r=e-n.length;t=r>0?(e=>{const t="".padStart(e," ");return e=>e+t})(r):(e=>t=>t.slice(e))(-r)}return t(n)},r=e=>Object.assign(Object.assign({},e),{tokens:Object.assign(Object.assign({},e.tokens),{start:n(e.tokens.start)})});return e=>{var{source:t}=e,n=Le(e,["source"]);return le.rewireSource(Object.assign(Object.assign({},n),{source:t.map(r)}))}},Me=Object.defineProperty({default:Re},"__esModule",{value:!0}),_e=ie((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.flow=void 0,t.flow=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}}));const $e={line:0,start:0,delimiter:0,postDelimiter:0,tag:0,postTag:0,name:0,postName:0,type:0,postType:0,description:0,end:0},qe=Object.keys($e),Ue=e=>le.isSpace(e)?`{${e.length}}`:e,Ve=e=>"|"+e.join("|")+"|",We=(e,t)=>Object.keys(t).map((n=>Ue(t[n]).padEnd(e[n])));var Ge=function({source:e}){if(0===e.length)return"";const t=Object.assign({},$e);for(const e of qe)t[e]=e.length;for(const{number:n,tokens:r}of e){t.line=Math.max(t.line,n.toString().length);for(const e in r)t[e]=Math.max(t[e],Ue(r[e]).length)}const n=[[],[]];for(const e of qe)n[0].push(e.padEnd(t[e]));for(const e of qe)n[1].push("-".padEnd(t[e],"-"));for(const{number:r,tokens:o}of e){const e=r.toString().padStart(t.line);n.push([e,...We(t,o)])}return n.map(Ve).join("\n")},ze=Object.defineProperty({default:Ge},"__esModule",{value:!0}),Je=ie((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.tokenizers=t.transforms=t.inspect=t.stringify=t.parse=void 0,t.parse=function(e,t={}){return Pe.default(t)(e)},t.stringify=Ie.default(),Object.defineProperty(t,"inspect",{enumerable:!0,get:function(){return ze.default}}),t.transforms={flow:_e.flow,align:je.default,indent:Me.default},t.tokenizers={tag:be.default,type:Ce.default,name:Ae.default,description:ke.default}})),Ke=ie((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.findJSDocComment=t.getDecorator=t.getJSDocComment=t.getReducedASTNode=void 0; | |||
/** | |||
* Obtained originally from {@link https://github.com/eslint/eslint/blob/master/lib/util/source-code.js#L313} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link doesn't seem to point to anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need to be fixed upstream.
@jasnell was that comment above intending for something akin to bundling like this PR, or using less code/transitive deps to achieve the goal? Right now it seems this PR has the same amount of code just in a different format/layout. Since this isn't being shipped at runtime and we don't even minify or bundle runtime deps for space it seems odd to me that we would bundle for our build steps. |
If we go with minifying, every update will change the entire line, and git is not optimized for that. |
We could mark these files as binary to workaround that: https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#Binary-Files |
Superseded by #41027. |
Alternative to #38279. Bundles and minifies ESLint plugin files to limit the number of lines committed to the repo.
/cc @targos @bmeck @nodejs/testing